﻿using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using SubstrateHelper.Data;

namespace SubstrateHelper.Models
{
    /// <summary>
    /// 调度（排产）
    /// </summary>
    public class Schedule
    {
        [Key]
        public int ID { get; set; }


        
        public int ProcessID { get; set; }


        public DateTime Date { get; set; }
        public int ScheduleNumber { get; set; }

        /// <summary>
        /// 订单号
        /// </summary>
        public string OrderSN { get; set; }











        /// <summary>
        /// 排产人ID
        /// </summary>        
        public string SchedulerId { get; set; }









        public bool IsDiscarded { get; set; }



        /// <summary>
        /// //////////////////////////////////////////////////////////////////////////////////////
        /// </summary>



        public virtual Process Process { get; set; }

        /// <summary>
        /// 排产人
        /// </summary>

        public IdentityUser Scheduler { get; set; }

        public List<ProcessRecord> ProcessRecords { get; set; } = new List<ProcessRecord>();

        public bool IsFinished { get; set; }

        public bool IsInspectionFinished { get; set; }

        //public bool IsTracingRecordFinished { get; set; }

        
        public string InputInventoryID { get; set; }

        public double InputQuantity { get; set; }

        
        public double OutputQuantity { get; set; }

        public string Remarks { get; set; }

        
        [NotMapped]
        public string InventoryID
        {
            get
            {
                if (Process != null)
                {
                    return $"{Process.OutputEntityName}{Date.Year:D4}{Date.Month:D2}{Date.Day:D2}-{ScheduleNumber:D2}";
                }
                return "";
            }
        }
    }

    
}
